
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/Public/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/Public/style/admin.css" media="all">
  <link id="layuicss-layer" rel="stylesheet"
    href="https://www.layui.com/admin/std/dist/layuiadmin/layui/css/modules/layer/default/layer.css?v=3.1.1"
    media="all">
</head>

<body>

  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">角色管理</div>
          <div class="layui-card-body">
            <table class="layui-hide" id="role-table-toolbar" lay-filter="role-table-toolbar"></table>
           

            <script type="text/html" id="role-table-isShow">
               <input type="checkbox" name="status" data-id="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="role-table-isShow"
               value="{{ d.status }}" {{ d.status == 1 ? 'checked' : '' }}>
            </script>
            <script type="text/html" id="role-table-toolbar-barDemo">
              <a class="layui-btn layui-btn-xs" lay-event="edit" lay-href="{:U('Rbac/access')}?rid={{d.id}}">配置权限</a>
              <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->
            </script>
          </div>
        </div>
      </div>
    </div>
  </div>


  <script src="/Public/layui/layui.js"></script>
  <script>
    layui.config({
      base: '/Public/' //静态资源所在路径
    }).extend({
      index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form'], function () {
      var $ = layui.$
        , admin = layui.admin
        , table = layui.table
        , form = layui.form
        , util = layui.util;
      table.render({
        elem: '#role-table-toolbar'
        , url: '{:U('Rbac/roleListApi')}'
        , toolbar: '#role-table-toolbar-add'
        , title: ''
        , cols: [[
          { type: 'checkbox', fixed: 'left' }
          , { field: 'id', title: '序号', sort: true }
          , { field: 'name',  title: '角色名称' }
          , { field: 'isshow', title: '开启状态', width: 200, templet: '#role-table-isShow', unresize: true }
          , { field: 'right', title: '操作', toolbar: '#role-table-toolbar-barDemo', minWidth: 150 }
        ]]
        , page: false
    });

    //监听状态操作
    form.on('switch(role-table-isShow)', function (obj) {
      var elem = $(obj.elem);
      var id = elem.attr("data-id");
      var status = obj.elem.checked ? 1 : 0;
      admin.req({
        url: '{:U('Rbac/setstatus')}',
        type: 'post',
        data: { "id": id, "status": status },
        done: function (res) {
          if (res.code == 0) {
            layer.msg(res.msg, { icon: 1 , shade: 0.3 });
            location.reload(index);
          } else {
            layer.msg(res.msg, { icon: 5 , shade: 0.3 });
          }

        }
              })
    });

  });
  </script>
</body>

</html>